package cn.tedu.store.product.webapi.controller;

import cn.tedu.store.commons.pojo.product.dto.BrandAddNewDTO;
import cn.tedu.store.commons.pojo.product.dto.BrandUpdateDTO;
import cn.tedu.store.commons.pojo.product.vo.BrandListItemVO;
import cn.tedu.store.commons.pojo.product.vo.BrandStandardVO;
import cn.tedu.store.commons.web.JsonPage;
import cn.tedu.store.product.service.IBrandService;
import cn.tedu.store.commons.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


import java.util.List;

/**
 * 品牌请求控制器
 *
 * @author RelentlessFlow
 * @version 0.0.1
 */
@Slf4j
@Api(tags = "03.品牌管理模块")
@Validated
@RestController
@RequestMapping("/brands")
public class BrandController {
    @Autowired
    private IBrandService brandService;

    @ApiOperation("添加品牌")
    @ApiOperationSupport(order = 100)
    @PostMapping("/add-new")
    public JsonResult<Void> addNew(@Validated BrandAddNewDTO brandAddNewDTO) {
        log.debug("开始处理[添加品牌]请求 参数:{}", brandAddNewDTO);
        brandService.addNew(brandAddNewDTO);
        return JsonResult.ok();
    }

    @ApiOperation("删除品牌")
    @ApiOperationSupport(order = 200)
    @ApiImplicitParam(name = "id", value = "品牌id", required = true, dataType = "long")
    @PostMapping("/{id:[0-9]+}/delete")
    public JsonResult<Void> delete(@PathVariable Long id) {
        log.debug("开始处理[删除品牌]请求 参数:{}", id);
        brandService.delete(id);
        return JsonResult.ok();
    }

    @ApiOperation("启用品牌")
    @ApiOperationSupport(order = 300)
    @ApiImplicitParam(name = "id", value = "品牌id", required = true, dataType = "long")
    @PostMapping("/{id:[0-9]+}/enable")
    public JsonResult<Void> setEnable(@PathVariable Long id) {
        log.debug("准备处理[启用品牌]请求 参数:{}", id);
        brandService.setEnable(id);
        return JsonResult.ok();
    }

    @ApiOperation("禁用品牌")
    @ApiOperationSupport(order = 310)
    @ApiImplicitParam(name = "id", value = "品牌id", required = true, dataType = "long")
    @PostMapping("/{id:[0-9]+}/disable")
    public JsonResult<Void> setDisable(@PathVariable Long id) {
        log.debug("准备处理[禁用品牌]请求 参数:{}", id);
        brandService.setDisable(id);
        return JsonResult.ok();
    }

    @ApiOperation("推荐品牌")
    @ApiOperationSupport(order = 320)
    @ApiImplicitParam(name = "id", value = "品牌id", required = true, dataType = "long")
    @PostMapping("/{id:[0-9]+}/recommend")
    public JsonResult<Void> setRecommend(@PathVariable Long id) {
        log.debug("准备处理[推荐品牌]请求 参数:{}", id);
        brandService.setRecommend(id);
        return JsonResult.ok();
    }

    @ApiOperation("取消推荐品牌")
    @ApiOperationSupport(order = 330)
    @ApiImplicitParam(name = "id", value = "品牌id", required = true, dataType = "long")
    @PostMapping("/{id:[0-9]+}/unrecommend")
    public JsonResult<Void> setNotRecommend(@PathVariable Long id) {
        log.debug("准备处理[取消推荐品牌]请求 参数:{}", id);
        brandService.setNotRecommend(id);
        return JsonResult.ok();
    }

    @ApiOperation("修改品牌信息")
    @ApiOperationSupport(order = 340)
    @ApiImplicitParam(name = "id", value = "品牌id", required = true, dataType = "long")
    @PostMapping("/{id:[0-9]+}/updateById")
    public JsonResult<Void> updateById(@PathVariable Long id, BrandUpdateDTO brandUpdateDTO) {
        log.debug("准备处理[修改品牌信息]请求 参数:{},{}", id, brandUpdateDTO);
        brandService.updateById(id,brandUpdateDTO);
        return JsonResult.ok();
    }

    @ApiOperation("获取品牌详情")
    @ApiOperationSupport(order = 400)
    @ApiImplicitParam(name = "id", value = "品牌id", required = true, dataType = "long")
    @GetMapping("/{id:[0-9]+}/getStandardById")
    public JsonResult<BrandStandardVO> getStandardById(@PathVariable Long id){
        log.debug("开始处理[获取品牌详情]请求 参数:{}",id);
        return JsonResult.ok(brandService.getStandardById(id));
    }

    @ApiOperation("获取品牌列表")
    @ApiOperationSupport(order = 410)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageSize", value = "每页记录数", dataType = "int"),
            @ApiImplicitParam(name = "pageNum", value = "页码", dataType = "int")
    })
    @GetMapping("")
    public JsonResult<JsonPage<BrandListItemVO>> list(
            @RequestParam(required = false, defaultValue = "1") Integer pageNum,
            @RequestParam(required = false, defaultValue = "10") Integer pageSize
            ){
        log.debug("开始处理[获取品牌列表]请求 参数:{},{}",pageNum,pageSize);
        return JsonResult.ok(brandService.list(pageNum, pageSize));
    }


}
